/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 *    
 */

package org.vineatoum.view.action;

import javax.swing.JPanel;
import java.awt.GridBagLayout;

import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import org.vineatoum.business.Cuve;
import org.vineatoum.business.action.operationactive.Ensemmensage;
import org.vineatoum.business.action.operationactive.Soutirage;
import org.vineatoum.model.abstraction.IVineaToumModel;

import com.toedter.calendar.JDateChooser;

public class EnsemmensagePanel extends JPanel {
	private static final long serialVersionUID = -6779005200522265769L;
	
	private JDateChooser dateChooserDate;
	private JSpinner spinnerLieQte;
	private JComboBox comboBoxCuveLie;

	/**
	 * Create the panel.
	 * 
	 * @param ensemmensage
	 * @param model
	 */
	public EnsemmensagePanel(IVineaToumModel model, Ensemmensage ensemmensage) {
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 0, 0, 144, 0, 0 };
		gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
		gbl_panel.columnWeights = new double[] { 1.0, 0.0, 0.0,
				1.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 1.0, 0.0, 0.0, 0.0, 1.0,
				Double.MIN_VALUE };
		setLayout(gbl_panel);
		
		List<Cuve> cuves = new ArrayList<Cuve>();
		for (Iterator<Cuve> iterator = Cuve.cuves.iterator(); iterator.hasNext();) {
			Cuve cuve = (Cuve) iterator.next();
			if(cuve.getName() != null && !cuve.getName().isEmpty()) {
				cuves.add(cuve);
			}
		}
		
		{
			JLabel lblDate = new JLabel("Date de l'ensemmensage");
			GridBagConstraints gbc_lblDate = new GridBagConstraints();
			gbc_lblDate.insets = new Insets(0, 0, 5, 5);
			gbc_lblDate.anchor = GridBagConstraints.EAST;
			gbc_lblDate.gridx = 1;
			gbc_lblDate.gridy = 1;
			add(lblDate, gbc_lblDate);
		}
		{
			dateChooserDate = new JDateChooser(ensemmensage.getDate());
			GridBagConstraints gbc_textField = new GridBagConstraints();
			gbc_textField.insets = new Insets(0, 0, 5, 5);
			gbc_textField.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField.gridx = 2;
			gbc_textField.gridy = 1;
			add(dateChooserDate, gbc_textField);
		}
		{
			JLabel lblLieQte = new JLabel("Quantité de lie");
			GridBagConstraints gbc_lblTemprature = new GridBagConstraints();
			gbc_lblTemprature.anchor = GridBagConstraints.EAST;
			gbc_lblTemprature.insets = new Insets(0, 0, 5, 5);
			gbc_lblTemprature.gridx = 1;
			gbc_lblTemprature.gridy = 2;
			add(lblLieQte, gbc_lblTemprature);
		}
		{
			spinnerLieQte = new JSpinner();
			spinnerLieQte.setModel(new SpinnerNumberModel(new Float(12),
					new Float(0), new Float(999999), new Float(0.1)));
			spinnerLieQte.setValue(ensemmensage.getLieQte());
			GridBagConstraints gbc_textField_1 = new GridBagConstraints();
			gbc_textField_1.insets = new Insets(0, 0, 5, 5);
			gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_1.gridx = 2;
			gbc_textField_1.gridy = 2;
			add(spinnerLieQte, gbc_textField_1);
		}
		{
			JLabel lblCuveLie = new JLabel(
					"Cuve source des lies");
			GridBagConstraints gbc_lblEstimation = new GridBagConstraints();
			gbc_lblEstimation.anchor = GridBagConstraints.EAST;
			gbc_lblEstimation.insets = new Insets(0, 0, 5, 5);
			gbc_lblEstimation.gridx = 1;
			gbc_lblEstimation.gridy = 3;
			add(lblCuveLie, gbc_lblEstimation);
		}
		{
			comboBoxCuveLie = new JComboBox();
			comboBoxCuveLie.setModel(new DefaultComboBoxModel(cuves.toArray()));
			comboBoxCuveLie.setSelectedItem(ensemmensage.getCuveLie());
			
			GridBagConstraints gbc_textField_3 = new GridBagConstraints();
			gbc_textField_3.insets = new Insets(0, 0, 5, 5);
			gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
			gbc_textField_3.gridx = 2;
			gbc_textField_3.gridy = 3;
			add(comboBoxCuveLie, gbc_textField_3);
		}
	}

	public Date getDate() {
		return dateChooserDate.getDate();
	}

	public Float getLieQte() {
		return (Float) spinnerLieQte.getValue();
	}

	public Cuve getCuveLie() {
		return (Cuve) comboBoxCuveLie.getSelectedItem();
	}
}
